package com.rabbiter.association.controller;


import com.rabbiter.association.msg.R;
import com.rabbiter.association.service.AliPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;


@Api(tags = "支付管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/pay")
public class AliPayController {


    private final AliPayService aliPayService;

    @ApiOperation(value = "支付预下单")
    @GetMapping("/aliPayPreorder/{orderId}")
    public String aliPayPreorder(@PathVariable("orderId") String orderId) {
        return aliPayService.aliPayPreorder(orderId);
    }

    @ApiOperation(value = "获取支付二维码内容")
    @GetMapping("/getQrCode/{orderId}")
    public R getQrCode(@PathVariable("orderId") String orderId) {
        return aliPayService.getQrCode(orderId);
    }

    @ApiOperation(value = "支付二维码")
    @GetMapping("/getQrCodeImage/{orderId}")
    public void getQrCodeImage(@PathVariable("orderId") String orderId, HttpServletResponse response) {
        aliPayService.getQrCodeImage(orderId, response);
    }

    @ApiOperation(value = "支付回调")
    @PostMapping("/notify")
    public R aliPayNotify(Map<String, String> params) {
        return aliPayService.aliPayNotify(params);
    }

    @ApiOperation(value = "查询订单")
    @GetMapping("/queryOrder/{orderId}")
    public R queryAliPayOrder(@PathVariable("orderId") String orderId) {
        return aliPayService.queryAliPayOrder(orderId);
    }

    @ApiOperation(value = "退款")
    @PostMapping("/refund")
    public R aliPayRefund(@RequestBody Map<String, String> params) {
        return aliPayService.aliPayRefund(params);
    }

    @ApiOperation(value = "退款查询")
    @GetMapping("/refundQuery/{orderId}")
    public R aliPayRefundQuery(@PathVariable("orderId") String orderId) {
        return aliPayService.aliPayRefundQuery(orderId);
    }

    @ApiOperation(value = "获取总账单")
    @GetMapping("/getBill")
    public R getAliPayBill(String billDate, String type) {
        return aliPayService.getAliPayBill(billDate, type);
    }

    @ApiOperation(value = "取消订单")
    @GetMapping("/cancelOrder/{orderId}")
    public R cancelAliPayOrder(@PathVariable("orderId") String orderId) {
        return aliPayService.cancelAliPayOrder(orderId);
    }

}
